/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution
{
    vector<int> ret;

public:
    vector<int> rightSideView(TreeNode* root)
    {
        dfs(root, 0);
        return ret;
    }
    void dfs(TreeNode* root, int path)
    {
        if (root == nullptr)
        {
            return;
        }
        if (path == ret.size())
        {
            ret.push_back(root->val);
        }
        dfs(root->right, path + 1);
        dfs(root->left, path + 1);
    }
};